package cn.edu.zafu.bigdata.x.wupeng.f;

import java.io.File;
import java.io.FileInputStream;

public class ExceptionDemo {
    public static void main(String[] args) {
        String [] arr={"Java","Python","C#"};
        int i=0;
//        while(i<4){
//            System.out.println(arr[i]);
//            i++;
//        }
        //产生一个随机数
        int num=(int)(Math.random()*10);
        try {
            if(num % 2 ==0){
                //ArrayIndexOutOfBoundsException
                System.out.println(arr[3]);
            }else if(num % 3 ==0) {
                //ArithmeticException
                i=1/0;
            }else {
                //构造一个文件不存在的异常
                File file=new File("D:/test.txt");
                FileInputStream fis=new FileInputStream(file);
                fis.read();
            }
        }

        catch (ArrayIndexOutOfBoundsException e) {
            //throw new RuntimeException(e);
            System.out.println("数组越界");
        }
        catch (ArithmeticException e){
            //throw new RuntimeException(e);
            System.out.println("除0错误");
        }

        catch (Exception e) {
            //throw new RuntimeException(e);
            System.out.println("未知错误");
        }

        finally {
            System.out.println("Final code block.");
        }
        System.out.println("Other code block.");
    }
}
